<?php
/**
 * Created by PhpStorm.
 * User: saeb
 * Date: 12/10/18
 * Time: 5:34 PM
 */
function last_db_change(){
    require(tiremanager_plugin_dir_path . 'formsconfig.php');
    require(tiremanager_plugin_dir_path . 'sellers_brands.php');
    global $wpdb;
    $table_name=$wpdb->prefix.$tire_table_quantities_without_prefix_name;
    $query= "select * from `$table_name` ORDER BY `date_updated` DESC LIMIT 200";
    $results=$wpdb->get_results($query);
    $row=0;
    $today=date('y-m-d',strtotime('now'));
    $search_criteria['start_date'] = $today;
    $search_criteria['end_date'] = $today;
    $count=GFAPI::count_entries($tire_gravity_form_id,$search_criteria);
//    var_dump($count);
?>
    <link rel="stylesheet" type="text/css"
          href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>

    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <table id="log" class="display" style="width:100%">
        <thead>
        <tr>
            <th>ردیف</th>
            <th>تاریخ</th>
                <th>عامل</th>
            <th>شماره فاکتور</th>
            <th>نوع لاستیک</th>
                <th>سایز</th>
                <th>موجودی</th>
                <th>ویرایش توسط</th>
        </tr>
        </thead>
        <tbody>

<?php
    foreach ($results as $result){
        echo "<tr>";
        echo "<td>";
        echo ++$row;
        echo "</td>";
        echo "<td>";
        $date=strtotime($result->date_updated);
        $jdate = jdate('Y-m-d H:i:s',$date);
        echo $jdate;
        echo "</td>";
        echo "<td>";
        echo $sellers_array[$result->tire_seller]['farsi_name'];
        echo "</td>";
        echo "<td>";
        echo $result->invoice_number;
        echo "</td>";
        echo "<td>";
        echo $result->tire_brand;
        echo "</td>";
        echo "<td>";
        echo    $result->tire_size;
        echo "</td>";
        echo "<td>";
        echo $result->tire_quantity;
        echo "</td>";
        echo "<td>";
        echo $result->added_by;
        echo "<td>";
        echo "</tr>";
    } ?>
        </tbody>
        <tfoot>
        <tr>
            <th>ردیف</th>
            <th>تاریخ</th>
            <th>عامل</th>
            <th>شماره فاکتور</th>
            <th>نوع لاستیک</th>
            <th>سایز</th>
            <th>موجودی</th>
            <th>ویرایش توسط</th>
        </tr>
        </tfoot>
    </table>
    <script>
        $(document).ready(function () {
                $('#log').DataTable({
                        "pageLength": 100,
                        "language": {
                            "search": "جست و جو",
                            "Show": "نمایش",
                            "paginate": {
                                "first": "اول",
                                "last": "آخر",
                                "next": "بعدی",
                                "previous": "قبلی"
                            },
                            "info": "صفحه _PAGE_ از _PAGES_",
                            "lengthMenu": "نمایش _MENU_ مورد",

                        },

                    }
                )
            }
        );
    </script>
    <?php
}